package com.proj.hot.utils;

import android.content.Context;
import android.graphics.Bitmap;

import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache;
import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.cache.memory.impl.UsingFreqLimitedMemoryCache;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
import com.nostra13.universalimageloader.core.display.SimpleBitmapDisplayer;
import com.nostra13.universalimageloader.core.download.BaseImageDownloader;
import com.nostra13.universalimageloader.utils.StorageUtils;

import java.io.File;


/**
 * 
 * 啥？
 * 
 */
public class ImageLoaderConfigFactory {

	public static DisplayImageOptions options;;
	public static DisplayImageOptions optionsNopic;;
	
	public synchronized static final DisplayImageOptions getOptions(){
		
		if (options==null) {
			 //����ImageLoader����
	        options = new DisplayImageOptions.Builder()
	                .cacheInMemory(true)
	                .cacheOnDisk(true)
	                .bitmapConfig(Bitmap.Config.RGB_565)
	                .displayer(new SimpleBitmapDisplayer()).build();
		}
		return options;
	}
	
public synchronized static final DisplayImageOptions getOptionsWithNopic(){
		
		if (optionsNopic==null) {
			 //����ImageLoader����
			optionsNopic = new DisplayImageOptions.Builder()
	                .cacheInMemory(true)
	                .cacheOnDisk(true)
//	                .showImageForEmptyUri(R.drawable.nopic)
//	                .showImageOnFail(R.drawable.nopic)
//	                .showImageOnLoading(R.drawable.nopic)
	                .bitmapConfig(Bitmap.Config.RGB_565)
	                .displayer(new SimpleBitmapDisplayer()).build();
		}
		return optionsNopic;
	}
	
	
	private static ImageLoaderConfiguration defaultImageLoaderConfiguration;

	public synchronized static final ImageLoaderConfiguration getDefaultConfig(
			Context context) {
		if (defaultImageLoaderConfiguration == null) {


			File cacheDir = StorageUtils.getOwnCacheDirectory(context, "yyst/cache/img");
			defaultImageLoaderConfiguration = new ImageLoaderConfiguration.Builder(context)
					.memoryCacheExtraOptions(480, 800) // max width, max height，即保存的每个缓存文件的最大长宽
					.threadPoolSize(3) //线程池内加载的数量
					.threadPriority(Thread.NORM_PRIORITY - 2)
					.denyCacheImageMultipleSizesInMemory()
					.diskCacheFileNameGenerator(new Md5FileNameGenerator()) //将保存的时候的URI名称用MD5 加密
					.memoryCache(new UsingFreqLimitedMemoryCache(2 * 1024 * 1024)) // You can pass your own memory cache implementation/你可以通过自己的内存缓存实现
					.memoryCacheSize(2 * 1024 * 1024) // 内存缓存的最大值
					.diskCacheSize(50 * 1024 * 1024)  // 50 Mb sd卡(本地)缓存的最大值
					.tasksProcessingOrder(QueueProcessingType.LIFO)
					// 由原先的discCache -> diskCache
					.diskCache(new UnlimitedDiskCache(cacheDir))//自定义缓存路径
					.imageDownloader(new BaseImageDownloader(context, 5 * 1000, 30 * 1000)) // connectTimeout (5 s), readTimeout (30 s)超时时间
					.writeDebugLogs() // Remove for release app
					.build();
			
			
		}
		return defaultImageLoaderConfiguration;
	}
	
	
	
	
	
}
